/*
  学习目标：优化创建store的写法
*/

import { legacy_createStore as createStore } from 'redux';

// 2. 使用单独的变量维持state的初始值: 命名 initState
const initState = { count: 0, msg: '123', title: '123' };

//  1. 使用单独的函数维护reducer, 命名: xxxReducer
function countReducer(state = initState, action) {
  console.warn('action  ----->  ', action);

  // 3.使用switch语句调换if语句,简化逻辑
  switch (action.type) {
    case 'add':
      return { count: state.count + 1 };

    case 'des':
      return { count: state.count - 1 };

    default:
      return state;
  }
}

const store = createStore(countReducer);
